package com.weetop.cfw.home_page.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.weetop.cfw.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BuildTypeAdapter extends BaseAdapter {
    public List<String> list = new ArrayList();
    public List<Boolean> list1 = new ArrayList();
    Context mContext;
    ViewHolder viewHolder;

    public BuildTypeAdapter(Context context, ArrayList<String> list, List<Boolean> list1) {
        mContext = context;
        this.list = list;
        this.list1 = list1;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_bottom_build_type, null);
            viewHolder = new ViewHolder();
            viewHolder.text = (TextView) convertView.findViewById(R.id.text);
            viewHolder.img = (ImageView) convertView.findViewById(R.id.img);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.text.setText(list.get(position));
        if (list1.get(position)) {
            viewHolder.img.setImageResource(R.mipmap.select_t);
        } else {
            viewHolder.img.setImageResource(R.mipmap.select_f);
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            int pos = position;

            @Override
            public void onClick(View v) {
                if (list1.get(pos)) {
                    list1.remove(pos);
                    list1.add(pos, false);
                } else {
                    list1.remove(pos);
                    list1.add(pos, true);
                }
                notifyDataSetChanged();
            }
        });
        return convertView;
    }

    class ViewHolder {
        public TextView text;
        public ImageView img;
    }
}
